package cn.texous.util.commons.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 格式校验工具类
 *
 * @author Showa.L
 * @since 2019/6/5 10:57
 */
public class CheckUtils {

    private static final String EMAIL_RGX =
            "^[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*"
                    + "@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[\\w](?:[\\w-]*[\\w])?$";

    /**
     * 校验邮箱
     *
     * @param email 邮箱
     * @return
     */
    public static Boolean isEmail(String email) {
        if (email == null)
            return false;
        Pattern pattern = Pattern.compile(EMAIL_RGX);
        Matcher matcher = pattern.matcher(email);
        return matcher.find();
    }

    /**
     * 校验密码
     *
     * @param pwd 密码
     * @return
     */
    public static Boolean badPwdLength(String pwd) {
        if (StringUtils.isTrimEmpty(pwd))
            return true;
        if (pwd.length() < 6
                || pwd.length() > 50)
            return true;
        return false;
    }

}
